﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using LTP.Common;

namespace CJJCH.Web
{
    public partial class ExpertAppraisal : System.Web.UI.Page
    {
        CJJCH.BLL.T_NET_Expert bll_expert = new BLL.T_NET_Expert();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.form1.DefaultButton = "btnSubmit";
            this.form1.DefaultFocus = "txtCompanyName";
            if (!IsPostBack)
            {
                InitRepater();
            }
            LTP.Common.ButtonClass.ButtonOnClick(this.Page, btnSubmit, "checkform()", false);
        }
        private void InitRepater()
        {
            #region MyRegion


            if (Request.QueryString["firstid"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["firstid"].Trim()))
            {
                lblFID.Text = Request.QueryString["firstid"].ToString();
                Top1.IIndex = Convert.ToInt32(lblFID.Text);
                Top1.FirstId = Convert.ToInt32(lblFID.Text);

            }
            if (Request.QueryString["secondid"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["firstid"].Trim()))
            {
                lblSID.Text = Request.QueryString["secondid"].ToString();
                Top1.SecondId = Convert.ToInt32(lblSID.Text);
            }
            if (Request.QueryString["thirdid"] != null && LTP.Common.CheckInput.CheckDigit(Request.QueryString["firstid"].Trim()))
            {
                lblTID.Text = Request.QueryString["thirdid"].ToString();
                Top1.ThirdId = Convert.ToInt32(Request.QueryString["thirdid"]);
            }

            if (Request.QueryString["keyword"] != null)
            {
                lblKeyWord.Text = Request.QueryString["keyword"].ToString();
                Top1.Keyword = lblKeyWord.Text;

            }
            if (Request.QueryString["typename"] != null)
            {

                lbltypeName.Text = Request.QueryString["typeName"].Trim();
                Top1.Typename = lbltypeName.Text;

            }
            #endregion
        }
        private void InitControl()
        {
            this.txtCompanyName.Attributes.Add("onblur", "StartMove()");
            this.txtCompanyName.Attributes.Add("onfocus", "StopMove()");
            this.txtCompanyAddress.Attributes.Add("onblur", "StartMove()");
            this.txtCompanyAddress.Attributes.Add("onfocus", "StopMove()");
            this.txtPostCode.Attributes.Add("onblur", "StartMove()");
            this.txtPostCode.Attributes.Add("onfocus", "StopMove()");



            this.txtContactName.Attributes.Add("onblur", "StartMove()");
            this.txtContactName.Attributes.Add("onfocus", "StopMove()");
            this.txtUserEmail.Attributes.Add("onblur", "StartMove()");
            this.txtUserEmail.Attributes.Add("onfocus", "StopMove()");
            this.txtOfficeTel.Attributes.Add("onblur", "StartMove()");
            this.txtOfficeTel.Attributes.Add("onfocus", "StopMove()");


            this.txtUserMobile.Attributes.Add("onblur", "StartMove()");
            this.txtUserMobile.Attributes.Add("onfocus", "StopMove()");
            this.txtProjectName.Attributes.Add("onblur", "StartMove()");
            this.txtProjectName.Attributes.Add("onfocus", "StopMove()");
            this.txtProjectAddress.Attributes.Add("onblur", "StartMove()");
            this.txtProjectAddress.Attributes.Add("onfocus", "StopMove()");



            this.txtJDMS.Attributes.Add("onblur", "StartMove()");
            this.txtJDMS.Attributes.Add("onfocus", "StopMove()");
            this.txtDXSCS.Attributes.Add("onblur", "StartMove()");
            this.txtDXSCS.Attributes.Add("onfocus", "StopMove()");
            this.txtRCSL.Attributes.Add("onblur", "StartMove()");
            this.txtRCSL.Attributes.Add("onfocus", "StopMove()");


            this.txtZCSL.Attributes.Add("onblur", "StartMove()");
            this.txtZCSL.Attributes.Add("onfocus", "StopMove()");
            this.txtHYDZ.Attributes.Add("onblur", "StartMove()");
            this.txtHYDZ.Attributes.Add("onfocus", "StopMove()");
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string error = checkInput();
            CJJCH.Model.T_NET_Expert model = new Model.T_NET_Expert();
            if (error == "")
            {
                model.ID = Guid.NewGuid();
                model.CompanyName = txtCompanyName.Text;
                model.CompanyAddress = txtCompanyAddress.Text;
                model.PostCode = txtPostCode.Text;
                model.ContactName = txtContactName.Text;
                model.UserEmail = txtUserEmail.Text;
                model.OfficeTel = txtOfficeTel.Text;
                model.UserMobile = txtUserMobile.Text;
                model.ProjectName = txtProjectName.Text;
                model.ProjectAddress = txtProjectAddress.Text;
                model.JDMS = Convert.ToDecimal(txtJDMS.Text);
                model.DXSCS = Convert.ToInt32(txtDXSCS.Text);
                model.RCSL = Convert.ToDecimal(txtRCSL.Text);
                model.ZCSL = Convert.ToDecimal(txtZCSL.Text);
                model.PSSJ = Convert.ToDateTime(txtPSSJ.Text);
                model.SBSJ = Convert.ToDateTime(txtSBSJ.Text);
                model.HYDZ = txtHYDZ.Text;
                try
                {
                    model.SCWJONEName = fileSCWJONE.FileName;
                }
                catch 
                {
                    model.SCWJONEName = "";
                }
                try
                {
                    model.SCWJTWOName = fileSCWJTWO.FileName;
                }
                catch
                {
                    model.SCWJTWOName = "";
                }
                model.WJSM = LTP.Common.StringClass.RemoveSQL(txtNote.Text.Trim());
                string fileType = ConfigHelper.GetConfigString("DownloadExt");
                int fileSize = ConfigHelper.GetConfigInt("DownloadSize");
                string UploadPic = ConfigHelper.GetConfigString("DownloadPath");
                string fileName = "";
                if (this.fileSCWJONE.FileName != "")
                {
                    error = FileClass.UploadFile2(fileSCWJONE, fileType, UploadPic, fileSize, ref fileName, 1);
                    if (string.IsNullOrEmpty(error))
                    {
                        model.SCWJONE = fileName;
                    }
                    else
                    {
                        LTP.Common.WindowClass.WindowBack(error);
                    }
                }
                //else
                //{
                //    LTP.Common.WindowClass.WindowBack("请选择上传文件1！");
                //}
                if (this.fileSCWJTWO.FileName != "")
                {
                    error = FileClass.UploadFile2(fileSCWJTWO, fileType, UploadPic, fileSize, ref fileName, 2);
                    if (string.IsNullOrEmpty(error))
                    {
                        model.SCWJTWO = fileName;
                    }
                    else
                    {
                        LTP.Common.WindowClass.WindowBack(error);
                    }
                }
                //else
                //{
                //    LTP.Common.WindowClass.WindowBack("请选择上传文件2！");
                //}
                model.FirstID = 4;
                model.SecondID = 12;
                model.ThirdID = 0;
                //model.FirstID = Convert.ToInt32(lblFID.Text);
                //model.SecondID = Convert.ToInt32(lblSID.Text);
                //model.ThirdID = Convert.ToInt32(lblTID.Text);

                error = bll_expert.AddExpert(model);
                if (error == "")
                {

                    LTP.Common.MessageBox.ShowAndRedirect(this, "添加成功！", "ExpertAppraisal.aspx?firstid=4&secondid=12&thirdid=0");
                }
                else
                {
                    LTP.Common.WindowClass.WindowBack(error);
                }

            }
            else
            {
                LTP.Common.WindowClass.WindowBack(error);
            }

        }
        protected string checkInput()
        {
            StringBuilder error = new StringBuilder();
            if (this.txtCompanyName.Text.Trim() == "")
            {
                error.Append("请输入单位名称！\\n");
            }
            if (this.txtCompanyAddress.Text.Trim() == "")
            {
                error.Append("请输入单位地址！\\n");
            }
            if (this.txtContactName.Text.Trim() == "")
            {
                error.Append("请输入联系人姓名！\\n");
            }

            if (this.txtPostCode.Text == "")
            {
                error.Append("请输入邮编！\\n");
            }
            else if (!LTP.Common.CheckInput.CheckPostcode(this.txtPostCode.Text.Trim()))
            {
                error.Append("请输入正确的邮编！\\n");
            }
            if (this.txtOfficeTel.Text == "")
            {
                error.Append("请输入固定电话");
            }
            if (this.txtUserMobile.Text == "")
            {
                error.Append("请输入手机号码！\\n");
            }
            else if (!LTP.Common.CheckInput.CheckMobile(this.txtUserMobile.Text.Trim()))
            {
                error.Append("请输入正确的手机号码！\\n");
            }
            if (this.txtUserEmail.Text == "")
            {
                error.Append("请输入e-mail地址！\\n");
            }
            else if (!LTP.Common.CheckInput.CheckEmail(this.txtUserEmail.Text.Trim()))
            {
                error.Append("请输入正确的e-mail地址！\\n");
            }
            if (this.txtProjectName.Text == "")
            {
                error.Append("请输入工程名称！\\n");
            }
            if (this.txtProjectAddress.Text == "")
            {
                error.Append("请输入工程地址！\\n");
            }
            if (this.txtJDMS.Text == "")
            {
                error.Append("请输入基低埋深（米）！\\n");
            }
            else if (!LTP.Common.CheckInput.CheckNumber(this.txtJDMS.Text.Trim()))
            {
                error.Append("请输入正确的基地埋深(米)");
            }
            if (this.txtDXSCS.Text == "")
            {
                error.Append("请输入地下水层数！\\n");
            }
            else if (!LTP.Common.CheckInput.CheckDigit(txtDXSCS.Text))
            {
                error.Append("请输入正确的地下水层数！\\n");
            }
            if (this.txtRCSL.Text == "")
            {
                error.Append("请输入日抽水量（方）！\\n");
            }
            else if (!LTP.Common.CheckInput.CheckNumber(this.txtRCSL.Text.Trim()))
            {
                error.Append("请输入正确的日抽水量（方）！\\n");
            }
            if (this.txtRCSL.Text == "")
            {
                error.Append("请输入总抽水量（方）！\\n");
            }
            else if (!LTP.Common.CheckInput.CheckNumber(this.txtRCSL.Text.Trim()))
            {
                error.Append("请输入正确的总抽水量（方）！\\n");
            }

            if (txtPSSJ.Text == "")
            {
                error.Append("请输入评审时间！\\n");
            }
            else if (!LTP.Common.CheckInput.CheckDateTime(txtPSSJ.Text))
            {
                error.Append("请输入正确的评审时间！\\n");
            }
            if (txtSBSJ.Text == "")
            {
                error.Append("请输入申报时间！\\n");
            }
            else if (!LTP.Common.CheckInput.CheckDateTime(txtSBSJ.Text))
            {
                error.Append("请输入正确的申报时间！\\n");
            }
            if (txtHYDZ.Text == "")
            {
                error.Append("请输入会议地址！\\n");
            }
            //if (fileSCWJONE.FileName == "")
            //{
            //    error.Append("请上传文件1！\\n");
            //}
            //if (fileSCWJTWO.FileName == "")
            //{
            //    error.Append("请上传文件2！\\n");
            //}
            DateTime endTime = Convert.ToDateTime(txtSBSJ.Text.Trim()).AddDays(7);
            if (Convert.ToDateTime(txtPSSJ.Text) < endTime)
            {
                error.Append("评审时间应定于申请日期一周以后！");
            }
            return error.ToString();
        }
    }
}